/*
 * TransaksiPembelianForm.java
 *
 * Created on November 10, 2011, 9:28 PM
 */
package Transaksi;

import Login.Koneksi;
import Login.Login;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.Timer;

/**
 *
 * @author FIONA
 */
public class TransaksiPembelianForm extends javax.swing.JPanel {

    /** Creates new form TransaksiPembelianForm */
    private int rowcount=0;
    public TransaksiPembelianForm(Login login) {

        initComponents();
        GregorianCalendar gc = new GregorianCalendar();
        tanggalTransaksiBeliChooser.setDate(gc.getTime());
        kasirTextField.setText(login.getLogin().getUserName());
        buatnomor();


        ActionListener taskPerformer = new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                jam2Label.setFont(new Font("jam", 1, 17));
                String nolJam = "";
                String nolMenit = "";
                String nolDetik = "";

                Date dt = new Date();

                int nilai_jam = dt.getHours();
                int nilai_menit = dt.getMinutes();
                int nilai_detik = dt.getSeconds();

                if (nilai_jam <= 9) {

                    nolJam = "0";
                }

                if (nilai_menit <= 9) {

                    nolMenit = "0";
                }

                if (nilai_detik <= 9) {

                    nolDetik = "0";
                }

                String jam = nolJam + Integer.toString(nilai_jam);
                String menit = nolMenit + Integer.toString(nilai_menit);
                String detik = nolDetik + Integer.toString(nilai_detik);
                // Menampilkan pada Layar
                jam2Label.setText("  " + jam + " : " + menit + " : " + detik + "  ");
            }
        };

        new Timer(1000, taskPerformer).start();

    }

    private void buatnomor() {
        try {
            Koneksi konek = new Koneksi();
            Statement statement = konek.getConnection().createStatement();
            String sql = "select no_transaksi_beli from pembelian ORDER by no_transaksi_beli desc";
            ResultSet rs = statement.executeQuery(sql);

            if (rs.next()) {
                int no_t = Integer.parseInt(rs.getString("no_transaksi_beli")) + 1;
                noTransaksiTextField.setText(Integer.toString(no_t));
            } else {
                int no_t = 1;
                noTransaksiTextField.setText(Integer.toString(no_t));
            }
            rs.close();
        } catch (Exception e) {
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        transaksiPembelianDesktopPane = new javax.swing.JDesktopPane();
        panel1 = new javax.swing.JPanel();
        judulLabel = new javax.swing.JLabel();
        tanggalLabel = new javax.swing.JLabel();
        jamLabel = new javax.swing.JLabel();
        kasirLabel = new javax.swing.JLabel();
        noTransaksiLabel = new javax.swing.JLabel();
        noTransaksiTextField = new javax.swing.JTextField();
        kasirTextField = new javax.swing.JTextField();
        tanggalTransaksiBeliChooser = new com.toedter.calendar.JDateChooser();
        jam2Label = new javax.swing.JLabel();
        panel2 = new javax.swing.JPanel();
        kodeBarangLabel = new javax.swing.JLabel();
        namaBarangLabel = new javax.swing.JLabel();
        hargaJualLabel = new javax.swing.JLabel();
        hargaBeliLabel = new javax.swing.JLabel();
        jumlahStokLabel = new javax.swing.JLabel();
        kodeBarangTF = new javax.swing.JTextField();
        namaBarangTF = new javax.swing.JTextField();
        hargaJualTF = new javax.swing.JTextField();
        hargaBeliTF = new javax.swing.JTextField();
        jumlahBarangTF = new javax.swing.JTextField();
        subtotalLabel = new javax.swing.JLabel();
        subtotalTextField = new javax.swing.JTextField();
        panel3 = new javax.swing.JPanel();
        kodePemasokLabel = new javax.swing.JLabel();
        namaPemasokLabel = new javax.swing.JLabel();
        alamatLabel = new javax.swing.JLabel();
        teleponLabel = new javax.swing.JLabel();
        personLabel = new javax.swing.JLabel();
        namaPemasokTextField = new javax.swing.JTextField();
        alamatTextField = new javax.swing.JTextField();
        teleponTextField = new javax.swing.JTextField();
        personTextField = new javax.swing.JTextField();
        kodePemasokTextField = new javax.swing.JTextField();
        panel4 = new javax.swing.JPanel();
        daftarBarangLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dataBarangTabel = new javax.swing.JTable();
        panel5 = new javax.swing.JPanel();
        totalLabel = new javax.swing.JLabel();
        bayarLabel = new javax.swing.JLabel();
        kembaliLabel = new javax.swing.JLabel();
        totalTextField = new javax.swing.JTextField();
        bayarTextField = new javax.swing.JTextField();
        kembaliTextField = new javax.swing.JTextField();
        panel6 = new javax.swing.JPanel();
        simpanButton1 = new javax.swing.JButton();
        ubahButton1 = new javax.swing.JButton();
        hapusButton1 = new javax.swing.JButton();
        batalButton1 = new javax.swing.JButton();

        panel1.setBackground(new java.awt.Color(51, 255, 204));

        judulLabel.setFont(new java.awt.Font("Castellar", 1, 24));
        judulLabel.setText("Alfamaret");

        tanggalLabel.setText("Tanggal");

        jamLabel.setText("Jam");

        kasirLabel.setText("Kasir");

        noTransaksiLabel.setText("No Transaksi");

        tanggalTransaksiBeliChooser.setDateFormatString("d MMM yyyy");

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addComponent(judulLabel)
                .addGap(79, 79, 79)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tanggalLabel, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(noTransaksiLabel, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(18, 18, 18)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(noTransaksiTextField)
                    .addComponent(tanggalTransaksiBeliChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))
                .addGap(34, 34, 34)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(jamLabel)
                        .addGap(18, 18, 18))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(kasirLabel)
                        .addGap(18, 18, 18)))
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(jam2Label, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
                        .addGap(151, 151, 151))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(kasirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(judulLabel)
                        .addComponent(tanggalLabel))
                    .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jamLabel)
                        .addComponent(jam2Label, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(tanggalTransaksiBeliChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(noTransaksiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kasirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kasirLabel)
                    .addComponent(noTransaksiLabel))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        panel1.setBounds(0, 0, 700, 80);
        transaksiPembelianDesktopPane.add(panel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel2.setBackground(new java.awt.Color(0, 255, 204));

        kodeBarangLabel.setText("Kode Barang");

        namaBarangLabel.setText("Nama Barang");

        hargaJualLabel.setText("Harga Jual");

        hargaBeliLabel.setText("Harga Beli");

        jumlahStokLabel.setText("Jumlah");

        kodeBarangTF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                kodeBarangTFKeyReleased(evt);
            }
        });

        jumlahBarangTF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jumlahBarangTFKeyPressed(evt);
            }
        });

        subtotalLabel.setText("Subtotal");

        subtotalTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                subtotalTextFieldKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(namaBarangLabel)
                    .addComponent(hargaJualLabel)
                    .addComponent(hargaBeliLabel)
                    .addComponent(jumlahStokLabel)
                    .addComponent(kodeBarangLabel)
                    .addComponent(subtotalLabel))
                .addGap(28, 28, 28)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(subtotalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                    .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(namaBarangTF)
                        .addComponent(hargaJualTF)
                        .addComponent(hargaBeliTF)
                        .addComponent(jumlahBarangTF)
                        .addComponent(kodeBarangTF, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(53, Short.MAX_VALUE))
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kodeBarangLabel)
                    .addComponent(kodeBarangTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(namaBarangLabel)
                    .addComponent(namaBarangTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hargaJualLabel)
                    .addComponent(hargaJualTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hargaBeliLabel)
                    .addComponent(hargaBeliTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jumlahStokLabel)
                    .addComponent(jumlahBarangTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(subtotalLabel)
                    .addComponent(subtotalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24))
        );

        panel2.setBounds(370, 80, 330, 170);
        transaksiPembelianDesktopPane.add(panel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel3.setBackground(new java.awt.Color(51, 255, 204));

        kodePemasokLabel.setText("Kode Pemasok");

        namaPemasokLabel.setText("Nama Pemasok");

        alamatLabel.setText("Alamat");

        teleponLabel.setText("Telepon");

        personLabel.setText("Person");

        kodePemasokTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                kodePemasokTextFieldKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout panel3Layout = new javax.swing.GroupLayout(panel3);
        panel3.setLayout(panel3Layout);
        panel3Layout.setHorizontalGroup(
            panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(namaPemasokLabel)
                    .addComponent(alamatLabel)
                    .addComponent(teleponLabel)
                    .addComponent(personLabel)
                    .addComponent(kodePemasokLabel))
                .addGap(28, 28, 28)
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(kodePemasokTextField)
                    .addComponent(alamatTextField)
                    .addComponent(teleponTextField)
                    .addComponent(personTextField)
                    .addComponent(namaPemasokTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
                .addContainerGap(116, Short.MAX_VALUE))
        );
        panel3Layout.setVerticalGroup(
            panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel3Layout.createSequentialGroup()
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(kodePemasokLabel)
                    .addComponent(kodePemasokTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(namaPemasokLabel)
                    .addComponent(namaPemasokTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(alamatLabel)
                    .addComponent(alamatTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(teleponLabel)
                    .addComponent(teleponTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(personLabel)
                    .addComponent(personTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(54, 54, 54))
        );

        panel3.setBounds(0, 80, 370, 170);
        transaksiPembelianDesktopPane.add(panel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel4.setBackground(new java.awt.Color(0, 255, 204));

        daftarBarangLabel.setFont(new java.awt.Font("Castellar", 1, 18));
        daftarBarangLabel.setText("Daftar Barang");

        dataBarangTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Kode Barang", "Nama Barang", "Harga", "Jumlah", "Pemasok", "Subtotal"
            }
        ));
        jScrollPane1.setViewportView(dataBarangTabel);

        javax.swing.GroupLayout panel4Layout = new javax.swing.GroupLayout(panel4);
        panel4.setLayout(panel4Layout);
        panel4Layout.setHorizontalGroup(
            panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel4Layout.createSequentialGroup()
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 630, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(daftarBarangLabel)))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        panel4Layout.setVerticalGroup(
            panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(daftarBarangLabel)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        panel4.setBounds(0, 250, 700, 130);
        transaksiPembelianDesktopPane.add(panel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel5.setBackground(new java.awt.Color(0, 255, 204));

        totalLabel.setText("Total");

        bayarLabel.setText("Bayar");

        kembaliLabel.setText("Kembali");

        bayarTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                bayarTextFieldKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout panel5Layout = new javax.swing.GroupLayout(panel5);
        panel5.setLayout(panel5Layout);
        panel5Layout.setHorizontalGroup(
            panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel5Layout.createSequentialGroup()
                .addGap(474, 474, 474)
                .addGroup(panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bayarLabel)
                    .addComponent(totalLabel)
                    .addComponent(kembaliLabel))
                .addGap(18, 18, 18)
                .addGroup(panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(totalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                    .addComponent(kembaliTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                    .addComponent(bayarTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                .addGap(29, 29, 29))
        );
        panel5Layout.setVerticalGroup(
            panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel5Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalLabel)
                    .addComponent(totalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bayarLabel)
                    .addComponent(bayarTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kembaliLabel)
                    .addComponent(kembaliTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panel5.setBounds(0, 450, 700, 100);
        transaksiPembelianDesktopPane.add(panel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel6.setBackground(new java.awt.Color(0, 255, 204));

        simpanButton1.setText("Simpan");
        simpanButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simpanButton1ActionPerformed(evt);
            }
        });

        ubahButton1.setText("Ubah");
        ubahButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ubahButton1ActionPerformed(evt);
            }
        });

        hapusButton1.setText("Hapus");

        batalButton1.setText("Batal");
        batalButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batalButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panel6Layout = new javax.swing.GroupLayout(panel6);
        panel6.setLayout(panel6Layout);
        panel6Layout.setHorizontalGroup(
            panel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(simpanButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hapusButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ubahButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(batalButton1)
                .addGap(428, 428, 428))
        );
        panel6Layout.setVerticalGroup(
            panel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel6Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(panel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simpanButton1)
                    .addComponent(hapusButton1)
                    .addComponent(ubahButton1)
                    .addComponent(batalButton1))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        panel6.setBounds(0, 380, 700, 70);
        transaksiPembelianDesktopPane.add(panel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(transaksiPembelianDesktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(transaksiPembelianDesktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void simpanButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simpanButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_simpanButton1ActionPerformed

    private void batalButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batalButton1ActionPerformed
        // TODO add your handling code here:
        kodePemasokTextField.setText("");
        namaPemasokTextField.setText("");
        alamatTextField.setText("");
        teleponTextField.setText("");
        personTextField.setText("");

        kodeBarangTF.setText("");
        namaBarangTF.setText("");
        hargaJualTF.setText("");
        hargaBeliTF.setText("");
        jumlahBarangTF.setText("");

    }//GEN-LAST:event_batalButton1ActionPerformed

    private void ubahButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ubahButton1ActionPerformed
        // TODO add your handling code here:
        kodePemasokTextField.setEditable(false);
        kodeBarangTF.setEditable(false);
//             if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
//         
//        }
    }//GEN-LAST:event_ubahButton1ActionPerformed

    private void kodePemasokTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kodePemasokTextFieldKeyReleased
        // TODO add your handling code here:
        try {
            Pemasok pemasok = new Pemasok();
            String kodePemasok = kodePemasokTextField.getText();
            pemasok.setKodePemasok(kodePemasok);
            pemasok=Pemasok.getKoneksi().cariPemasok(pemasok);

            String namaPemasok = pemasok.getNamaPemasok();
            String alamatPemasok = pemasok.getAlamat();
            String teleponPemasok = pemasok.getNoTelepon();
            String personPemasok = pemasok.getPerson();

            namaPemasokTextField.setText(namaPemasok);
            alamatTextField.setText(alamatPemasok);
            teleponTextField.setText(teleponPemasok);
            personTextField.setText(personPemasok);


        }
        catch (SQLException ex) {
            Logger.getLogger(TransaksiPembelianForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(panel3, "Data Pemasok belum ada. Silahkan masukan terlebih dahulu data pemasok");
           
        }

    }//GEN-LAST:event_kodePemasokTextFieldKeyReleased

    private void bayarTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bayarTextFieldKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_bayarTextFieldKeyPressed

    private void jumlahBarangTFKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jumlahBarangTFKeyPressed
        // TODO add your handling code here:
          if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            int row = dataBarangTabel.getSelectedRow();
            int urut=0;
            double sum=0;

            Double hargaBeli = Double.parseDouble(hargaBeliTF.getText());
            Double jumlah = Double.parseDouble(jumlahBarangTF.getText());
            Double subtotal=hargaBeli*jumlah;
            subtotalTextField.setText(String.valueOf(subtotal));

            String kodeBarang = kodeBarangTF.getText();
            String namaBarang = namaBarangTF.getText();
            Double harga = Double.parseDouble(hargaBeliTF.getText());
            Double jumlahBarang = Double.parseDouble(jumlahBarangTF.getText());
            Double subtotal2 = Double.parseDouble(subtotalTextField.getText());

            
            dataBarangTabel.setValueAt(kodeBarangTF.getText(), rowcount, 0);
            dataBarangTabel.setValueAt(namaBarangTF.getText(), rowcount, 1);
            dataBarangTabel.setValueAt(hargaBeliTF.getText(), rowcount, 2);
            dataBarangTabel.setValueAt(jumlahBarangTF.getText(), rowcount, 3);
            dataBarangTabel.setValueAt(namaPemasokTextField.getText(), rowcount, 4);
            dataBarangTabel.setValueAt(subtotalTextField.getText(), rowcount, 5);

           rowcount++;
           sum=sum+subtotal;
           totalTextField.setText(String.valueOf(sum));


        }
    }//GEN-LAST:event_jumlahBarangTFKeyPressed

    private void kodeBarangTFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kodeBarangTFKeyReleased
        // TODO add your handling code here:
//             try {
           Barang barang = new Barang();
            String kodeBarang= kodeBarangTF.getText();
            barang.setKodeBarang(kodeBarang);
//            barang=Barang.getBarang().getAllBarang();


            String namaBarang = barang.getNamaBarang();
            Double hargaJual = barang.getHargaJual();
            Double hargaBeli = barang.getHargaBeli();
            Double jumlah =barang.getJumlah();

            namaBarangTF.setText(namaBarang);
            hargaJualTF.setText(String.valueOf(hargaJual));
            hargaBeliTF.setText(String.valueOf(hargaBeli));
            jumlahBarangTF.setText(String.valueOf(jumlah));

//        }
//        catch (SQLException ex) {
//            Logger.getLogger(TransaksiPembelianForm.class.getName()).log(Level.SEVERE, null, ex);
//            JOptionPane.showMessageDialog(panel3, "Data Barang belum ada. Silahkan masukan terlebih dahulu data barang");
//
//        }
    }//GEN-LAST:event_kodeBarangTFKeyReleased

    private void subtotalTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_subtotalTextFieldKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_subtotalTextFieldKeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel alamatLabel;
    private javax.swing.JTextField alamatTextField;
    private javax.swing.JButton batalButton1;
    private javax.swing.JLabel bayarLabel;
    private javax.swing.JTextField bayarTextField;
    private javax.swing.JLabel daftarBarangLabel;
    private javax.swing.JTable dataBarangTabel;
    private javax.swing.JButton hapusButton1;
    private javax.swing.JLabel hargaBeliLabel;
    private javax.swing.JTextField hargaBeliTF;
    private javax.swing.JLabel hargaJualLabel;
    private javax.swing.JTextField hargaJualTF;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jam2Label;
    private javax.swing.JLabel jamLabel;
    private javax.swing.JLabel judulLabel;
    private javax.swing.JTextField jumlahBarangTF;
    private javax.swing.JLabel jumlahStokLabel;
    private javax.swing.JLabel kasirLabel;
    private javax.swing.JTextField kasirTextField;
    private javax.swing.JLabel kembaliLabel;
    private javax.swing.JTextField kembaliTextField;
    private javax.swing.JLabel kodeBarangLabel;
    private javax.swing.JTextField kodeBarangTF;
    private javax.swing.JLabel kodePemasokLabel;
    private javax.swing.JTextField kodePemasokTextField;
    private javax.swing.JLabel namaBarangLabel;
    private javax.swing.JTextField namaBarangTF;
    private javax.swing.JLabel namaPemasokLabel;
    private javax.swing.JTextField namaPemasokTextField;
    private javax.swing.JLabel noTransaksiLabel;
    private javax.swing.JTextField noTransaksiTextField;
    private javax.swing.JPanel panel1;
    private javax.swing.JPanel panel2;
    private javax.swing.JPanel panel3;
    private javax.swing.JPanel panel4;
    private javax.swing.JPanel panel5;
    private javax.swing.JPanel panel6;
    private javax.swing.JLabel personLabel;
    private javax.swing.JTextField personTextField;
    private javax.swing.JButton simpanButton1;
    private javax.swing.JLabel subtotalLabel;
    private javax.swing.JTextField subtotalTextField;
    private javax.swing.JLabel tanggalLabel;
    private com.toedter.calendar.JDateChooser tanggalTransaksiBeliChooser;
    private javax.swing.JLabel teleponLabel;
    private javax.swing.JTextField teleponTextField;
    private javax.swing.JLabel totalLabel;
    private javax.swing.JTextField totalTextField;
    private javax.swing.JDesktopPane transaksiPembelianDesktopPane;
    private javax.swing.JButton ubahButton1;
    // End of variables declaration//GEN-END:variables
}
